package cn.regexp.business.web.controller;


import cn.hutool.core.util.ObjectUtil;
import cn.regexp.common.base.page.TablePageInfo;
import cn.regexp.domain.ShopFeedback;
import cn.regexp.query.FeedbackQuery;
import cn.regexp.service.IFeedbackService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 意见反馈控制器
 */
@Slf4j
@Controller
@RequestMapping("business/feedback")
public class FeedbackController {
    //模板前缀
    private static final String prefix = "business/feedback/";

    @Autowired
    private IFeedbackService feedbackService;

    //页面------------------------------------------------------------
    //列表
    @RequiresPermissions("business:feedback:view")
    @RequestMapping("/listPage")
    public String listPage() {
        return prefix + "list";
    }

    //数据-----------------------------------------------------------
    //列表
    @RequiresPermissions("business:feedback:list")
    @RequestMapping("/query")
    @ResponseBody
    public TablePageInfo<ShopFeedback> query(FeedbackQuery qo) {
        PageHelper.startPage(qo.getPageNum(), qo.getPageSize());
        QueryWrapper<ShopFeedback> wrapper = new QueryWrapper<>();
        wrapper.like(ObjectUtil.isNotEmpty(qo.getKeyword()), "content", qo.getKeyword())
                .or()
                .like(ObjectUtil.isNotEmpty(qo.getKeyword()), "device_model", qo.getKeyword());
        return new TablePageInfo<>(feedbackService.list(wrapper));
    }
}
